import { defineStore } from "../index";
import type { UserState } from "@model/store";
import type { Menu } from "@model/views";

const useUserStore = defineStore("user", {
	state: (): UserState => ({
		token: null,
		permissions: ["boss", "admin"],
		menuList: [],
	}),
	getters: {
		getToken: state => state.token,
		getPermissions: state => state.permissions,
		getMenuList: state => state.menuList,
	},
	actions: {
		login(value: string) {
			this.token = value;
		},
		loginOut() {
			this.token = null;
		},
		setPermissions(value: string[]) {
			this.permissions = value;
		},
		setMenuList(value: Menu[]) {
			this.menuList = value;
		},
	},
});

export default useUserStore;
